<template>
  <div class="tabs-box flex">
    <router-link
      v-for="(item, index) of tabsList"
      :key="index"
      :to="{name: item.name }"
      class="position-r flex pad-l-15 pad-r-15"
      @click.stop="changeTabs(index)"
    >
      <span :class="index === tabsIndex ? 'active-tab': 'disactive-tab'" class="cursor-p v-align-c tab-item font-16">
        {{ item.title }}
      </span>
    </router-link>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue'
import { useRoute } from 'vue-router'

export default defineComponent({
  setup() {
    const route = useRoute()
    const tabsIndex = ref(0)
    watch(() => route.path, (newValue, oldValue) => {
      tabsIndex.value = newValue === '/center/order/platform-order' ? 1 : 0
    })
    interface ITabslist {
      title: string,
      name: string
    }
    const tabsList:ITabslist[] = [
      {
        title: '我的订单',
        name: 'my-order'
      },
      {
        title: '平台订单',
        name: 'platform-order'
        }
    ]
    const changeTabs = (index:number):void => {
      tabsIndex.value = index
    }
    return {
      tabsList,
      tabsIndex,
      changeTabs
    }
  }
})
</script>

<style lang="scss" scoped>
.tabs-box {
  height: 61px;
  border-bottom: 1px solid #F5F6FA;
  box-sizing: border-box;
  padding-left: 27px;
  & > span {
    position: relative;
    height: 100%;
    padding-left: 15px;
    padding-right: 17px;
    margin-left: 27px;
  }
  .active-tab {
    color: #182245;
    &::after {
      content: '';
      display: block;
      position: absolute;
      width: 100%;
      border-bottom: 3px solid #0C213F;
      bottom: -1.5px;
      left: 0;
    }
  }
  .disactive-tab {
    color: #999999;
  }
}
</style>
